Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gnovm): fix crash stack overflow when print value of self referencing structure #2851

Conversation

MikaelVallenet
Copy link
Member

@MikaelVallenet MikaelVallenet commented Sep 26, 2024

Fix stack overflow when printing value of recursive self referencing struct

resolve #2850

Methodology used

I added a stack to store the struct type already processed, then each time we process a struct i check if this struct type is already processed, if yes i remplace it by an empty struct so it avoid crash on recursive.

func gno2GoType(t Type, seen map[Type]reflect.Type) reflect.Type
		if val, ok := seen[t]; ok {
			return val
		}

		placeholder := reflect.TypeOf(struct{}{})
		seen[t] = placeholder
Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

Copy link

codecov bot commented Sep 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.95%. Comparing base (577c462) to head (49ff9dc).
Report is 10 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2851      +/-   ##
==========================================
+ Coverage   60.92%   60.95%   +0.02%     
==========================================
  Files         564      564              
  Lines       75267    75389     +122     
==========================================
+ Hits        45854    45950      +96     
- Misses      26041    26048       +7     
- Partials     3372     3391      +19     
Flag Coverage Δ
contribs/gnodev 61.46% <ø> (ø)
contribs/gnofaucet 14.46% <ø> (ø)
gno.land 67.17% <ø> (ø)
gnovm 65.78% <100.00%> (+<0.01%) ⬆️
misc/genstd 80.54% <ø> (ø)
misc/logos 19.88% <ø> (-0.36%) ⬇️
tm2 62.07% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Sep 27, 2024
@MikaelVallenet MikaelVallenet changed the title WIP - fix(gnovm): fix crash stack overflow when print value of self referencing structure fix(gnovm): fix crash stack overflow when print value of self referencing structure Sep 27, 2024
@MikaelVallenet MikaelVallenet marked this pull request as ready for review September 30, 2024 09:10
@MikaelVallenet
Copy link
Member Author

Ready for review ✅

Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you don't spend too much effort improving gonative, as we want to remove it eventually: #1361.

In the meantime, LGTM.

@thehowl
Copy link
Member

thehowl commented Oct 2, 2024

Thanks for the PR; I'll close this as a won't fix as a real solution for printing these structures in gonative would require named type support in reflect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

bug: crash stack overflow / size exceeded when printing value of self referencing structure
3 participants